/*****************************************************************************
 *   Copyright 2005 Tim A Wang
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 ****************************************************************************/
package com.jb.framework;

import com.jb.framework.pm.PersistencyException;


public interface PersistentManager {
    /**
     * Tests whether this pm is read only.
     * @return true if it is readonly.
     * @throws PersistencyException
     */
    public boolean isReadOnly() throws PersistencyException;
    /**
     * Creates a bean in the persistent storage. It does not perform transactional
     * operations.
     * @param bean a java object to be saved.
     * @throws PersistencyException if failed the operation
     */
    public void create(Persistable bean) throws PersistencyException;

    /**
     * Deletes a bean in the persistent storage. It does not perform transactional
     * operations.
     * @param bean a java object to be deleted.
     * @throws PersistencyException if failed the operation
     */
    public void delete(Persistable bean) throws PersistencyException;

    /**
     * Finds a bean in the persistent storage by id. It does not perform transactional
     * operations.
     * @param childClass a java class to be found.
     * @param id object identify the bean.
     * @throws PersistencyException if failed the operation
     */
    public Object findById(Class childClass, 
                           Object id) throws PersistencyException;

    /**
     * Loads a bean from the persistent storage by id. It does not perform transactional
     * operations.
     * @param bean a java object to be found.
     * @throws PersistencyException if failed the operation
     */
    public boolean load(Persistable bean) throws PersistencyException;

    /**
     * Saves a bean from the persistent storage by id. It does not perform transactional
     * operations.
     * @param bean a java object to be found.
     * @throws PersistencyException if failed the operation
     */
    public void save(Persistable bean) throws PersistencyException;
    /**
     * Saves a bean from the persistent storage by id. It does not perform transactional
     * operations.
     * @param bean to be saved
     * @param saveChildren if true, all its children would be saved as well.
     * @throws PersistencyException
     */
    public void save(Persistable bean, 
                     boolean saveChildren) throws PersistencyException;
}
